<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class LaborCompany extends Model
{
    use HasFactory;

    protected $fillable = [
        'admin_id',
        'company_id',
        'role_id',
        'name',
        'number',
        'bank',
        'bank_number',
        'contacts',
        'contact_mobile',
        'company_type',
        'brief',
        'files',
        'remarks',
        'business_cert',
        'security_cert',
        'legal_cert',
        'safety_cert',
        'human_resources_cert',
    ];
    const POSTONLY = [
        'admin_id',
        'company_id',
        'role_id',
        'name',
        'number',
        'bank',
        'bank_number',
        'contacts',
        'contact_mobile',
        'company_type',
        'brief',
        'files',
        'remarks',
        'business_cert',
        'security_cert',
        'legal_cert',
        'safety_cert',
        'human_resources_cert',
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function admin()
    {
        return $this->hasOne(Admin::class,'id','admin_id')->select('id','name');
    }

    public function resources()
    {
        return $this->hasMany(ResourceBind::class,'source_id','id')->where('model','LaborCompany')->with('resource');
    }

}
